package com.leyou.common.bean;

import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author zqq
 * @ClassName Pager
 * @Description: 分页数据类
 * @date 2020/3/5-9:17
 */
@NoArgsConstructor
public class Pager<T> {

    /** 默认显示条数 */
    public static final int PAGE_SIZE = 10;

    /** 当前页数 */
    private int currentPage;

    /** 每页显示条数 */
    private int pageSize = PAGE_SIZE;

    /** 排序 */
    private String orderBy;

    /** 升序或者倒序 */
    private String order;

    /** 返回结果 */
    private List<T> result;

    /** 总条数 */
    private long total;

    /** 总页数 */
    private int totalPage;

    public Pager(int currentPage, int pageSize, String orderBy, String order) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.orderBy = orderBy;
        this.order = order;
    }

    public static int getPageSize() {
        return PAGE_SIZE;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getTotalPage() {
        this.totalPage = (int) (total / pageSize);
        if (this.total % this.pageSize == 0) {
            return totalPage;
        } else {
            return totalPage + 1;
        }
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
}
